< previous page page_574 next page >

Page 574
Type.gifListing 14.27. Updating the errHandler method.
' build full message
    strMsg = errMsg(objErrColl, intType)
    '
    ' write it out, if allowed           <<< new code
    If errLogFlag = True Then     <<< new code
        LogError strMsg                  <<< new code
    End If                                       <<< new code
    '
    ' evaluate things
    Select Case errOption
That's the end of the code to add logging to the error handler. Save the project and compile the ActiveX DLL. Once the DLL has been successfully compiled, close this project and open the test project you built earlier.
Open the Form_Load event of the frmTest form and add two lines to set the LogFileName and WriteLogFlag properties of the errHandler object. Listing 14.28 shows how to modify the code.
Type.gifListing 14.28. Modifying the Form_Load event to include error logging.
Private Sub Form_Load()
    '
    Data1.DatabaseName = "junk"
    Set objErr = New errHandler
    '
    objErr.WriteLogFlag = True
    objErr.LogFileName = App.Path & "\" & App.EXEName & ".log"
    '
End Sub
Now, when you run the project, each error is logged to a file with the same name as the application in the same folder as the application. In the preceding example, a file called errTest.log was created in the C:\TYSDBVB5\SOURCE\CHAP14\ folder. Listing 14.29 shows the contents of this error log file.
Type.gifListing 14.29. Contents of the errTest.log file.
05-Feb-97 5:27:01 AM
<3024> Couldn't find file 'junk'. (in DAO.Workspace).

05-Feb-97 5:27:08 AM
<11> Division by zero (in prjTest)

 
< previous page page_574 next page >

If you like this book, buy it!